]> git.r.bdr.sh - rbdr/map/blame - Map/Presentation/Base Components/MapRender/MapNotes.swift
Update to support notes + new style
[rbdr/map] / Map / Presentation / Base Components / MapRender / MapNotes.swift
CommitLineData
fdb4633d
RBR
1import SwiftUI
2
3struct MapNotes: View {
4
5 let mapSize: CGSize
6 let lineWidth: CGFloat
7 let notes: [Note]
8
9 let maxWidth = 400.0
10
11
12 var body: some View {
13 ForEach(notes, id: \.id) { note in
14 Text(note.text.replacingOccurrences(of: "\\n", with: "\n")).font(.theme.axisLabel)
15 .padding(2.0)
16 .background(.white)
17 .foregroundColor(.map.labelColor)
18 .border(Color.map.vertexColor, width: lineWidth)
19 .frame(minWidth: 16.0, maxWidth: maxWidth, alignment: .topLeading)
20 .offset(
21 CGSize(
22 width: w(note.position.x),
23 height: h(note.position.y)
24 )
25 )
26 }
27 }
28
29 func h(_ dimension: CGFloat) -> CGFloat {
30 max(0.0, min(mapSize.height, dimension * mapSize.height / 100.0))
31 }
32
33 func w(_ dimension: CGFloat) -> CGFloat {
34 max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0))
35 }
36}
37
38struct MapNotes_Previews: PreviewProvider {
39 static var previews: some View {
40 MapNotes(
41 mapSize: CGSize(width: 400.0, height: 400.0), lineWidth: 1.0,
42 notes: [
43 Note(id: 0, position: CGPoint(x: 50.0, y: 50.0), text: "Notes can have a lot more text, so we need to make sure that they're resized correctly"),
44 ])
45 }
46}